package com.fangyahao.role.utils;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

public class HttpRequestPost {

    public static Map stringToMap(ServletRequest request) throws IOException {
        Map map = new HashMap();

        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        String lines;
        StringBuffer sb = new StringBuffer("");
        while ((lines = reader.readLine()) != null) {

            lines = URLDecoder.decode(lines, "utf-8");
            sb.append(lines);
        }

        String str = sb.toString();
        boolean result = false;
        try {
            Object obj=JSON.parse(str);
            map = (Map) obj;
            result = true;
        } catch (Exception e) {
            result=false;
        }




        if (!("".equals(str)) &&result==false) {
            map = TransJson.stringToObject(str);
        }
        return map;
    }



}
